package a09_贪心算法;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * <p>
 * a14_根据身高重建队列复习1
 * </p>
 *
 * @author flyduck
 * @since 2025/1/15
 */
public class a14_根据身高重建队列复习1 {
    public int[][] reconstructQueue(int[][] people) {
        people = Arrays.stream(people)
                .sorted((item1, item2) -> {
                    if (item1[0] == item2[0]) {
                        return item1[1] - item2[1];
                    }
                    return item2[0] - item1[0];
                }).toArray(int[][]::new);

        List<int[]> result = new LinkedList<>();
        for (int i = 0; i < people.length; i++) {
            result.add(people[i][1],people[i]);
        }

        return result.toArray(new int[result.size()][2]);
    }
}
